home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / UDPDUMP.C < prev    next >
C/C++ Source or Header  |  1988-04-03  |  883b  |  46 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "udp.h"
  7.  
  8. extern FILE *trfp;
  9.  
  10. /* Dump a UDP header */
  11. void
  12. udp_dump(bpp,source,dest,check)
  13. struct mbuf **bpp;
  14. int32 source,dest;
  15. int check;        /* If 0, bypass checksum verify */
  16. {
  17.     struct udp udp;
  18.     struct pseudo_header ph;
  19.     int16 csum;
  20.  
  21.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  22.         return;
  23.  
  24.     fprintf(trfp,"UDP:");
  25.  
  26.     /* Compute checksum */
  27.     ph.source = source;
  28.     ph.dest = dest;
  29.     ph.protocol = UDP_PTCL;
  30.     ph.length = len_mbuf(*bpp);
  31.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  32.         check = 0;    /* No checksum error */
  33.  
  34.     ntohudp(&udp,bpp);
  35.  
  36.     fprintf(trfp," %u->%u",udp.source,udp.dest);
  37.     fprintf(trfp," len %u",udp.length);
  38.     if(udp.checksum == 0)
  39.         check = 0;
  40.     if(check)
  41.         fprintf(trfp," CHECKSUM ERROR (%u)",csum);
  42.  
  43.     fprintf(trfp,"\n");
  44. }
  45.  
  46.